qui(function (require, exports, module) {
    Broadcast.Util = $.extend(true, {}, EpgWeb.Util, {
        formatter: {
            online: function (cellvalue, options, rowObject) {
                var onlineKey = "onlineKey_" + rowObject.key;
                return "<label class='radio inline'><input type='radio' value='1' name='" + onlineKey + "' >启用</label><label class='radio inline'><input type='radio'  value='-1' name='" + onlineKey + "'>不启用</label>"
            },
            region: function (cellvalue, options, rowObject) {
                var regionKey = "regionKey_" + rowObject.key;
                return "<label class='radio inline'><input type='radio' value='1' name='" + regionKey + "' >启用</label><label class='radio inline'><input type='radio'  value='-1' name='" + regionKey + "'>不启用</label>"
            }
        },
        makeBlackList: function (regName) {
            var htmlArr = [];
            var channel = Broadcast.Dao.getChannel();
            if (channel['liveType'] == 3) {
                htmlArr.push('<div style="height:100%;width:100%;position:absolute;background: rgba(0, 0, 0, 0.1);z-index:1;"></div>');
            }
            htmlArr.push('<div  class="control-group"> <span style="background-color:#ff8c00 ;color: #ffffff;padding-right: 15px;padding-left: 10px;border-bottom-right-radius: 8px" >地域黑名单</span></div>')
            htmlArr.push('<div class="control-group">');
            htmlArr.push('<label class="checkbox inline"><input type="checkbox" name="area_select" value="3_95_香港,3_148_澳门,3_228_台湾,6_301_海外">海外地区限制：香港、澳门、台湾、海外</label>');
            //   htmlArr.push('<label class="checkbox inline"><input type="checkbox" name="area_select" value="3_2_上海,3_1_北京,4_3001_广东省广州市,4_3003_广东省深圳市">一线城市限制：上海、北京、广州、深圳</label>');
            htmlArr.push('<label class="checkbox inline"><input type="checkbox" name="area_select" value="3_2_上海,3_1_北京,4_3001_广州,4_3003_深圳">一线城市限制：上海、北京、广州、深圳</label>');
            htmlArr.push('<label class="checkbox inline"><input type="checkbox" name="area_select" value="3_1_北京,3_4_天津">京津地区限制：北京、天津</label>');
            htmlArr.push('</div>');
            htmlArr.push('<div  class="control-group"><span>自定义地域限制</span>');
            htmlArr.push('<input type="text" class="inline" name="localSuggest" placeholder="输入地区关键字检索" autocomplete="off">')
            htmlArr.push('</div>');
            htmlArr.push('<div  class="control-group"><span>地域展现控制：</span><label class="checkbox inline"><input type="checkbox" name="regionRejectSearch" value="0" >屏蔽搜索</label></div>');
            return '<div style="border-style: dashed ;border-width: 1px;position: relative;">' + htmlArr.join("") + "</div>";
        },

        makePlatformZone: function (index) {
            var self = this;
            var htmlArr = [];
            var regName = "platform_" + index;
            htmlArr.push(self.onlineZone(regName));
            htmlArr.push(self.searchZone(regName));
            htmlArr.push(self.broadcastDelayZone(regName));
            if(Broadcast.Config.Mode == "channel"){
                htmlArr.push(self.broadcastApplyZone(regName));
            }
            htmlArr.push(self.makeBlackList(regName));
            return htmlArr.join("");
        },

        onlineZone: function (radioName) {
            var htmlArr = [];
            htmlArr.push('<div class="control-group">');
            htmlArr.push('<span>上下线状态：</span>');
            htmlArr.push('<input type="radio" name="' + radioName + '" value="1"><span>上线</span>');
            htmlArr.push('<input type="radio" name="' + radioName + '" value="0"><span>下线</span>');
            htmlArr.push('</div>');
            return htmlArr.join("");
        },

        searchZone: function (regName) {
            var htmlArr = [];
            htmlArr.push('<div class="control-group">');
            htmlArr.push('<span>展现控制：</span><label class="checkbox inline"><input type="checkbox" name="rejectSearch" value="0" >屏蔽搜索</label>');
            htmlArr.push('</div>');
            return htmlArr.join("");
        },

        broadcastDelayZone: function (regName) {
            var htmlArr = [];
            htmlArr.push('<div class="control-group" style="display:none">');
            htmlArr.push('<span>PC网页端延时：</span><input  name="' + regName + '_delay" type="text"> 秒');
            htmlArr.push('</div>');
            return htmlArr.join("");
        },
        broadcastApplyZone: function (regName) {
            var htmlArr = [];
            htmlArr.push('<div class="control-group">');
            htmlArr.push('<label class="col-xs-2 control-label" style="width: 170px">频道播控是否立即对节目生效：<span class="form-must">*</span></label><label class="radio inline"><input type="radio" name="app_on_episode" value="true" >是</label><label class="radio inline"><input type="radio" name="app_on_episode" value="false" >否' +
                '</label>');
            htmlArr.push('</div>');
            var lastDate = new Date();
            lastDate.setHours(0);
            lastDate.setMinutes(0);
            lastDate.setSeconds(0);
            lastDate.setMilliseconds(0);
            lastDate.setTime(lastDate.getTime()+86400000*2);
            htmlArr.push('<div class="control-group" ><span style="color: red">注： 未开始2天内节目的播控才能被频道播控覆盖！</span>即从现在到'+Broadcast.Util.quickDateFormat(lastDate)+'之前的节目的播控可以被覆盖。</div>');

            return htmlArr.join("");
        },
        makeTabPanel: function (obj) {
            var divIndex = obj.key;
            var htmlArr = [];
            var tabPanelName = "tabPanel_" + divIndex;
            htmlArr.push('<div id="' + tabPanelName + '">');
            htmlArr.push('<div class="container">');
            htmlArr.push('<div name="locationControl" >' + Broadcast.Util.makePlatformZone(divIndex) + '</div>');
            htmlArr.push('</div>');
            htmlArr.push('</div>');
            return htmlArr.join("");
        },
        fixLocaltion: function (originValue) {
            var regFixLocaltion = /^\W*省|市$/g;
            if (originValue == null) {
                return "";
            }
            return originValue.replace(regFixLocaltion, "");
        },
        formatToLocationItem: function (inputStr) {
            var self = this;
            var ret = [];
            var items = inputStr.split(",")
            $.each(
                items, function (i, item) {
                    item = item.split('_');
                    var itemData = {};
                    itemData["label"] = self.fixLocaltion(item[2]);
                    itemData["id"] = item[0] + "_" + item[1];
                    ret.push(itemData);
                }
            );
            return ret;
        },


        formatCompareString: function (obj) {
            return obj.availableStatus + "|" + obj.blacklist + "|" + obj.liveDelayTime + "|" + obj.rejectSearch + "|" + obj.regionRejectSearch;
        }

    });


});